<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dberp-menu-top">
            <?php echo $this->HelpUrl('shopOrderGoods'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box erp-box">

                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead>
                            <tr class="erp-bg-thead">
                                <th width="12%"><?php echo $this->translate('商品编号'); ?></th>
                                <th><?php echo $this->translate('商品名称'); ?></th>
                                <th width="10%"><?php echo $this->translate('商品规格'); ?></th>
                                <th width="6%"><?php echo $this->translate('数量'); ?></th>
                                <th width="10%"><?php echo $this->translate('订单号'); ?></th>
                                <th width="6%"><?php echo $this->translate('订单状态'); ?></th>
                                <th width="8%"><?php echo $this->translate('所属商城'); ?></th>
                                <th width="10%"><?php echo $this->translate('仓库'); ?></th>
                                <th width="8%"><?php echo $this->translate('配货状态'); ?></th>
                                <th width="10%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('order_state')->setEmptyOption('选择');
                            $sForm->get('distribution_state')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <td>
                                    <?php echo $this->formElement($sForm->get('goods_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('goods_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('goods_name')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('goods_name'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('goods_spec')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('goods_spec'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('start_buy_num')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('end_buy_num')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_buy_num'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_buy_num'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('shop_order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('shop_order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('app_id')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('app_id'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('warehouse_id')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('warehouse_id'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('distribution_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('distribution_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php
                                    $formData = $sForm->getData();
                                    if(!empty(array_filter($formData))
                                        || $formData['order_state'] != ''
                                        || $formData['warehouse_id'] != ''
                                        || $formData['distribution_state'] != ''
                                        || $formData['app_id'] != '') { ?>
                                        <a href="<?php echo $this->url('app-shop-order-goods');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>

                            <?php if($this->orderGoodsList->getTotalItemCount() > 0) { foreach ($this->orderGoodsList as $goods) { ?>
                                <tr>
                                    <td><?php echo $this->escapeHtml($goods->getGoodsSn()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getGoodsName()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getGoodsSpec()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getBuyNum()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getOneShopOrder()->getShopOrderSn()); ?></td>
                                    <td><?php echo $this->shop()->shopOrderState($goods->getOneShopOrder()->getShopOrderState()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getOneShopOrder()->getOneApp()->getAppName()); ?></td>
                                    <td><?php echo $this->escapeHtml($goods->getWarehouseName()); ?></td>
                                    <td><?php echo $this->shop()->shopDistributionState($goods->getDistributionState(), 2); ?></td>
                                    <td>
                                        <?php if($goods->getDistributionState() == 3) { ?>
                                            <a href="<?php echo $this->url('app-shop-order-goods',
                                                ['action'=>'distributionGoods', 'id'=>$goods->getOrderGoodsId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>"
                                               class="btn btn-xs btn-success"><i class="fa fa-check"></i> <?php echo $this->translate('匹配商品'); ?></a>
                                        <?php } ?>
                                        <?php if($goods->getDistributionState() == -1) { ?>
                                            <a href="<?php echo $this->url('app-shop-order-goods',
                                                ['action'=>'finishDistribution', 'id'=>$goods->getOrderGoodsId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>"
                                               class="btn btn-xs btn-info"><i class="fa fa-info-circle"></i> <?php echo $this->translate('商品补货'); ?>
                                            </a>
                                        <?php } ?>
                                    </td>
                                </tr>
                            <?php } } else { ?>
                                <tfoot>
                                <tr>
                                    <td colspan="8"><?php echo $this->translate('暂无订单商品信息'); ?></td>
                                </tr>
                                </tfoot>
                            <?php } ?>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?php echo $this->paginationControl($this->orderGoodsList, 'Sliding', 'layout/page', ['route' => 'app-shop-order-goods']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>